package com.example.testapp

import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.google.gson.reflect.TypeToken
import com.qiantoon.networkdsl.base.BaseNetworkApi
import com.qiantoon.networkdsl.http.request
import com.qiantoon.networkdsl.support.PreferencesUtil

/**
 * @Package com.example.testapp
 * @ClassName MainViewModel
 * @Author caostgrace
 * @Date 2021/4/13
 * @Email liaobing@qiantoon.com
 * @Desc
 */
class MainViewModel:ViewModel() {

    val loginState = MutableLiveData<Boolean>()

    fun login(){
        request<DoctorInfo> {
            loader {
                BaseNetworkApi.getService(DoctorService::class.java)
                        .login("2", "18011482047", "", "000000")
            }
            onSuccess {
                PreferencesUtil.getInstance().setUserInfo(it)
                loginState.value = true
            }
            onError {
                it.printStackTrace()
                loginState.value = false
                false
            }
            type {
                object : TypeToken<DoctorInfo>() {}.type
            }
        }
    }

    fun queryMyHealthyCircleList(){
        request<MineHealthCircleBean> {
            loader {
                BaseNetworkApi.getService(DoctorService::class.java)
                        .queryMyHealthyCircleList("1","1","")
            }
            onSuccess {
                Log.e("====>",it.toString())
            }
            onError {
                it.printStackTrace()
                false
            }
            type {
                object : TypeToken<MineHealthCircleBean>() {}.type
            }
        }
    }

}